$(function() {
	$('#editFileName').on('show.bs.modal', function(data) {
		// 执行一些动作...
		var folderId = data.relatedTarget.attributes.dataid.nodeValue;
		var folder_name = data.relatedTarget.attributes.dataname.nodeValue;
		$('#editArea').val(folder_name	);
		$("#folderId").val(folderId);
	})
	$('#deleteFolder').on('show.bs.modal', function(data) {
		// 执行一些动作...
		var folderId = data.relatedTarget.attributes.dataid.nodeValue;
		$("#folderId").val(folderId);
	})

	$('.saveFileName').on('click', function() {
		var folderName = $("#editArea").val();
		var folderId = $("#folderId").val();
		if (folderName == '我的文件' || folderName == '项目文件') {
			alert("名称有误");
			return false;
		}
		$.ajax({
			type : "post",
			url : "/folder/updateFolder",
			data : {
				"name" : folderName,
				"id":folderId
			},
			dataType : "json",
			success : function(data) {
				if (data.status == true) {
					$('#editFileName').modal('hide');
					location.reload(); 
				}
			}
		});
	});
	$('.newCreat').click(function() {
		$('.creatBar').stop().slideToggle(300);
	});
	$('.cNoBtn').click(function() {
		$('.creatBar').stop().slideUp(300);
	});

	$(".cYesBtn").click(function() {
		var folderName = $("#folderName").val();
		if (folderName == '' || folderName == null) {
			alert("请输入文件夹名称");
			return false;
		}
		if (folderName == '我的文件' || folderName == '项目文件') {
			alert("名称有误");
			return false;
		}
		$.ajax({
			type : "post",
			url : "/folder/addFolder",
			data : {
				"name" : folderName
			},
			dataType : "json",
			success : function(data) {
				if (data.status == true) {
					location.reload(); 
				}
			}
		});
	})
	
	$("#searchFolder i").click(function(){
		var searchName = $("#searchName").val();
		var parentId = $("#parentId").val();
		var type = $("#type").val();
		if(parentId == '' || parentId == null) {
			parentId = 0;
		}
		if(type == '' || type == null) {
			type = 0;
		}
		if(searchName == '') {
			alert("请输入文件夹名称");
			return false;
		}
		
		$.ajax({
			type:"post",
			url:"/folder/list",
			data:{"name":searchName,"parentId":parentId,"type":type},
			success:function(data){
				$("#mytable").html(data);
			}
		})
	})	

	$('#searchName').keydown(function(e){
		if(e.keyCode==13){
			var searchName = $("#searchName").val();
			var parentId = $("#parentId").val();
			var type = $("#type").val();
			if(parentId == '' || parentId == null) {
				parentId = 0;
			}
			if(type == '' || type == null) {
				type = 0;
			}
			if(searchName == '') {
				alert("请输入文件夹名称");
				return false;
			}
			$.ajax({
				type:"post",
				url:"/folder/list",
				data:{"name":searchName,"parentId":parentId,"type":type},
				success:function(data){
					$("#mytable").html(data);
				}
			})
		}
	});
	
})
$('#delFolderOK').click(function(){
	var id = $("#folderId").val();
	$.ajax({
		type : "post",
		url : "/folder/deleteFolder",
		data : {
			"id" : id
		},
		dataType : "json",
		success : function(data) {
			location.reload(); 
		}
	});
});

var method;
method = function(){
	var pageNo = $('#pageNo').val();
	var searchName = $("#searchName").val();
	var parentId = $("#parentId").val();
	var type = $("#type").val();
	if(type == '' || type == null) {
		type = 2;
	}
	if(parentId == '' || parentId == null) {
		parentId = 0;
	}
	$.ajax({
		type:"post",
		url:"/folder/list",
		data:{"pageNo":pageNo,"name":searchName, "parentId":parentId,"type":type},
		success:function(data){
			$("#mytable").html(data);
		}
	});
}